//
//  LSZStatus.swift
//  醒浪微博
//
//  Created by 雷顺哲 on 16/7/12.
//  Copyright © 2016年 LSZ. All rights reserved.
//

import UIKit
//微博模型数据
class LSZStatus: NSObject {
//    发布微博时间
    var created_at: String?
//    微博id
    var id: Int64 = 0
//    微博内容
    var text: String?
//    来源
    var source: String?
    
//    关注用户对象
    var user: LSZUser?
//    转发数
    var reposts_count: Int = 0
//    评论数
    var comments_count: Int = 0
//    赞的数量
    var attitudes_count: Int = 0
//    转发微博对象
    var retweeted_status: LSZStatus?
//    配图信息
    var pic_urls: [LSZStatusPictureInfo]?
    
//    kvc构造函数
    init(dic: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
//      手动字典转模型
        if key == "user" {
            guard let dic = value as? [String : AnyObject] else{
                return
            }
//            代码执行到此一定是字典格式
            user = LSZUser(dic: dic)
        } else if key == "retweeted_status"{
            
            guard let dic = value as? [String: AnyObject] else {
                return
            }
//            代码执行到此,说明格式一定正确
            retweeted_status = LSZStatus(dic: dic)
            
        }else if key == "pic_urls"{
            guard let dicArray = value as? [[String: AnyObject]] else {
                return
            }
            var tempArray = [LSZStatusPictureInfo]()
            for dic in dicArray {
                let pictureInfo = LSZStatusPictureInfo(dic: dic)
                tempArray.append(pictureInfo)
            }
            pic_urls = tempArray
        
        }else {
            super.setValue(value, forKey: key)
        }
    }
    
    
    
    
    
//    防止崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
